﻿using FasterWPF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace FasterWPFDemo
{
    public static class CustomDialogExample
    {
        public static Border InitializeDialogExample(Canvas baseWindowCanvas, string canvasGuidKey)
        {
            Border customDialog = new Border();

            //Test CheckBox and RadioButton
            CheckBox cbx = new CheckBox();
            cbx.Initialize(ContainerType.HorizontalPanel, true, false);
            cbx.BeginComposite<CheckBox>().AddText<CheckBox>(0, 0, "Water").EndComposite<CheckBox, CheckBoxArgs>(null);

            RadioButton rdbi1 = new RadioButton();
            rdbi1.Initialize(ContainerType.HorizontalPanel, false, false, "metalsGroup");
            rdbi1.BeginComposite<RadioButton>().AddText<RadioButton>(0, 0, "Iron").EndComposite<RadioButton, RadioButtonArgs>(null);

            RadioButton rdbi2 = new RadioButton();
            rdbi2.Initialize(ContainerType.HorizontalPanel, false, false, "metalsGroup");
            rdbi2.BeginComposite<RadioButton>().AddText<RadioButton>(0, 0, "Steel").EndComposite<RadioButton, RadioButtonArgs>(null);
            
            customDialog.Initialize(300, 300, ContainerType.HorizontalPanel, Brushes.Black, new Thickness(1), Brushes.WhiteSmoke);
            customDialog.BeginSettings<Border>().SetItemBorderSettings<Border>(294, 294, Brushes.LightGray, new Thickness(3)).EndSettings<Border>();

            //StackPanel
            StackPanel stkPanel1 = new StackPanel();
            stkPanel1.SetBackgroundColor(Brushes.WhiteSmoke);
            stkPanel1.Initialize(300D, 300D, ContainerType.HorizontalPanel, Orientation.Vertical);

            baseWindowCanvas.BeginComposite(canvasGuidKey)
                .AddExisting<Border, Canvas>(0, 0, customDialog)
                .EndComposite<Canvas, CanvasArgs>(new CanvasArgs(300D, 300D, 500));

            customDialog.BeginComposite()
              .AddExisting<StackPanel, Border>(0, 0, stkPanel1)
              .EndComposite<Border, BorderArgs>(null);

            stkPanel1.BeginSettings<StackPanel>()
                .Set<CheckBox, StackPanel>(0, 1, "Margin", new Thickness(5))
                .Set<RadioButton, StackPanel>(0, 2, "Margin", new Thickness(5, 3, 5, 1))
                .Set<RadioButton, StackPanel>(0, 3, "Margin", new Thickness(5, 0, 5, 3))
                .SetTextPadding<StackPanel>(0, 0, new Thickness(3))
                .Set<Rectangle, StackPanel>(0, 4, "Fill", Brushes.WhiteSmoke)
                .Set<Rectangle, StackPanel>(0, 4, "Stroke", Brushes.WhiteSmoke)
                .Set<Rectangle, StackPanel>(0, 4, "Height", 150D)
                .Set<Rectangle, StackPanel>(0, 4, "Width", 100D)
                .Set<Border, StackPanel>(0, 5, "Margin", new Thickness(215D, 0, 0, 0))
                .SetFont<StackPanel>(0, 0, "Calibri", 17, FontWeights.Bold, FontStyles.Oblique)
                .EndSettings<StackPanel>();

            stkPanel1.BeginComposite().AddText<StackPanel>(0, 0, "Dialog").EndComposite<StackPanel, StackPanelArgs>(null);

            stkPanel1.BeginComposite()
            .AddExisting<CheckBox, StackPanel>(0, 1, cbx)
            .SubscribeEventOnChild<CheckBox, StackPanel, RoutedEventArgs>(0, 1, "Checked", ((o, revargs) => { System.Windows.MessageBox.Show("Checkbox has been checked!"); }), chbx => { return true; })
            .SubscribeEventOnChild<CheckBox, StackPanel, RoutedEventArgs>(0, 1, "Unchecked", ((o, revargs) => { System.Windows.MessageBox.Show("Checkbox has been un-checked!"); }), chbx => { return true; })
            .EndComposite<StackPanel, StackPanelArgs>(null);

            stkPanel1.BeginComposite()
           .AddExisting<RadioButton, StackPanel>(0, 2, rdbi1)
           .EndComposite<StackPanel, StackPanelArgs>(null);

            stkPanel1.BeginComposite()
           .AddExisting<RadioButton, StackPanel>(0, 3, rdbi2)
           .EndComposite<StackPanel, StackPanelArgs>(null);

            Border borderButton3 = new Border();
            borderButton3.MaxHeight = 50;
            borderButton3.Initialize(double.NaN, double.NaN, ContainerType.HorizontalPanel, Brushes.Indigo, new Thickness(2), Brushes.PowderBlue, new CornerRadius(10), new Thickness(0), new Thickness(1));

            borderButton3.BeginSettings<Border>()
                .SetTextPadding<Border>(0, 0, new Thickness(4))
                .SubscribeMouseSingleClickOnBorder<Border>((o, ev) =>
                {   //CLOSE DIALOG
                    if (baseWindowCanvas.IsCompositeOnParent<Canvas>(canvasGuidKey))
                    {
                        baseWindowCanvas.RemoveByKey<Canvas>(canvasGuidKey);
                    }
                })
                .EndSettings<Border>();

            borderButton3.SetMouseOverColorOnBorder(Brushes.Orange);

            borderButton3.BeginComposite()
                .AddText<Border>(0, 0, "  Cancel  ")
                .EndComposite<Border, BorderArgs>(null);

            stkPanel1.BeginComposite()
                     .AddAnything<Rectangle, StackPanel>(0, 4)
                     .EndComposite<StackPanel, StackPanelArgs>(null);

            stkPanel1.BeginComposite()
                     .AddExisting<Border, StackPanel>(0, 5, borderButton3)
                     .EndComposite<StackPanel, StackPanelArgs>(null);

            return customDialog;
        }
    }
}
